//
//  XLHTTPSessionManager+UserInfo.m
//  XiangLove
//
//  Created by 陈宪栋 on 2017/11/30.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "XLHTTPSessionManager+UserInfo.h"
#import "XLUserInfoModel.h"
#import <ReactiveCocoa.h>
#import "XLTalkedPeopleModle.h"
//#import <UIApplication+YYAdd.h>

@implementation XLHTTPSessionManager (UserInfo)
- (RACSignal *)getUserInfoWithUserId:(NSString *)userId secretKey:(NSString *)secretKey {
    NSString *URLString = @"/api/v2/UserInfo/GetUserInfo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?: @""     forKey:@"userid"];
    [parameters setObject:QudaoName    forKey:@"qudao"];
    [self.requestSerializer setValue:secretKey ?: @"" forHTTPHeaderField:@"sign"];
    return [self XLV2GET:URLString parameters:parameters resultClass:[XLUserInfoModel class]];
}

- (RACSignal *)modifyUserInfoWithUserId:(NSString *)userId nickName:(NSString *)nickName headImg:(NSString *)headImg sex:(UserSex)sex age:(NSInteger)age hostCity:(NSString *)hostCity secretKey:(NSString *)secretKey {
    NSString *URLString = @"Api/v1/UserInfo/EditUserInfo";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId ?: @""     forKey:@"Id"];
    [parameters setObject:QudaoName     forKey:@"QuDao"];
    [parameters setObject:nickName ?: @""   forKey:@"NickName"];
    [parameters setObject:headImg ?: @""    forKey:@"HeadImg"];
    [parameters setObject:@(sex)            forKey:@"Sex"];
    [parameters setObject:@(age)            forKey:@"Age"];
    [parameters setObject:hostCity ?: @""                   forKey:@"HostCity"];
    [self.requestSerializer setValue:secretKey ?: @"" forHTTPHeaderField:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
}

-(RACSignal *)getZFBPlayOrder:(NSString *)UserId giftId:(NSString *)giftId TransType:(NSString *)transType payType:(NSString *)payType FeeType:(NSString *)FeeType Money:(NSString *)Money PrivateInfo:(NSString *)privateInfo Remarks:(NSString *)Remarks Months:(NSString *)Months secretKey:(NSString *)secretKey{
    
    NSString *URLString = @"/Api/v1/AliPay/CreateAliPayOrder";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:UserId      ?:@""  forKey:@"UserId"];
    [parameters setObject:giftId      ?:@""  forKey:@"GiftId"];
    [parameters setObject:transType   ?:@""  forKey:@"TransType"];
    [parameters setObject:payType     ?:@""  forKey:@"PayType"];
    [parameters setObject:FeeType     ?:@""  forKey:@"FeeType"];
    [parameters setObject:Money       ?:@""  forKey:@"Money"];
    [parameters setObject:privateInfo ?:@""  forKey:@"PrivateInfo"];
    [parameters setObject:Remarks     ?:@""  forKey:@"Remarks"];
    [parameters setObject:Months      ?:@""  forKey:@"Months"];

    [self.requestSerializer setValue:secretKey ?: @"" forHTTPHeaderField:@"sign"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

-(RACSignal *)getWechatPayOrderWithUserId:(NSString *)UserId GiftId:(NSString *)GiftId TransType:(NSString *)TransType PayType:(NSString *)PayType FeeType:(NSString *)FeeType Money:(NSString *)Money PrivateInfo:(NSString *)PrivateInfo Remarks:(NSString *)Remarks Months:(NSString *)Months  userIp:(NSString *)userIp AppId:(NSString *)AppId secretKey:(NSString *)secretKey
{
    NSString *URLString = @"Api/v1/WeChatPay/CreateWeChatPayOrder";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:UserId      ?:@""  forKey:@"UserId"];
    [parameters setObject:GiftId      ?:@""  forKey:@"GiftId"];
    [parameters setObject:TransType   ?:@""  forKey:@"TransType"];
    [parameters setObject:PayType     ?:@""  forKey:@"PayType"];
    [parameters setObject:FeeType     ?:@""  forKey:@"FeeType"];
    [parameters setObject:Money       ?:@""  forKey:@"Money"];
    [parameters setObject:PrivateInfo ?:@""  forKey:@"PrivateInfo"];
    [parameters setObject:Remarks     ?:@""  forKey:@"Remarks"];
    [parameters setObject:Months      ?:@""  forKey:@"Months"];
    [parameters setObject:userIp      ?:@""  forKey:@"userIp"];
    [parameters setObject:AppId       ?:@""  forKey:@"AppId"];
    [self.requestSerializer setValue:secretKey ?: @"" forHTTPHeaderField:@"sign"];
    [self.requestSerializer setValue:@"1"             forHTTPHeaderField:@"appId"];
    [self.requestSerializer setValue:QudaoName    forHTTPHeaderField:@"qudao"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self POST:URLString parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

-(RACSignal *)getTalkedPeopleNumbersuserld:(NSString *)userId pageIndex:(NSString *)pageIndex pageCount:(NSString *)pageCount secretKey:(NSString *)secretKey{
    NSString *URLString = @"Api/v1/TalkedPeople/GetTalkedPeople";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:userId    ?:@"" forKey:@"userId"];
    [parameters setObject:pageIndex ?:@"" forKey:@"pageIndex"];
    [parameters setObject:pageCount ?:@"" forKey:@"pageCount"];
    [self.requestSerializer setValue:secretKey ?: @"" forHTTPHeaderField:@"sign"];
    return [self XLPOST:URLString parameters:parameters resultClass:[XLTalkedPeopleModle class]];
}

-(RACSignal *)getTalkedOnlinePeoplesWithAppID
{
    NSString *URLString = @"/Api/v1/Matching/Online";
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:QudaoName                                         forKey:@"qudao"];
    [parameters setObject:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]   forKey:@"version"];
    [parameters setObject:@"1"                                                  forKey:@"appid"];
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
    
}

- (RACSignal *)getMatchPicData
{
    NSString *URLString = @"/api/v1/Matching/GetMatchPic";
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
        NSURLSessionDataTask *task = [self GET:URLString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            [subscriber sendNext:responseObject];
            [subscriber sendCompleted];
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            [subscriber sendError:error];
        }];
        return [RACDisposable disposableWithBlock:^{
            [task cancel];
        }];
    }];
}
@end
